<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Storage;

class FileUploadController extends Controller
{
    public function store(Request $request){
    	$fileName = $request->file('file')->getClientOriginalName();
        $dirName = date('Ymd');
        $path = Storage::disk('inside_file')->putFileAs($dirName,
            $request->file('file'), $fileName);
        $urlPrefix = Storage::disk('inside_file')->url($dirName);

        return response()->json([
            'status' => 'success',
            'message' => '上传成功',
            'data' => [
	            'file_name' => $fileName,
	            'url_prefix' => $urlPrefix,
	            'url' => $urlPrefix . '/' . $fileName,
	        ],
    	]);
    }
}
